from django.db import models


# Create your models here.

class Fans(models.Model):
    """
    粉丝表：
    用户(关系属性)、 粉丝(关系属性)、 是否互相关注 、 关注时间、互关时间
    """
    user = models.ForeignKey(to='auth.User',on_delete=models.CASCADE,
                             related_name="fans_list",
                             verbose_name="用户",db_comment="用户")

    fans = models.ForeignKey(to='auth.User',on_delete=models.CASCADE,
                                 verbose_name="粉丝用户",db_comment="粉丝用户")

    follow_time = models.DateTimeField(auto_now_add=True,verbose_name="关注时间",db_comment="关注时间")

    is_mutual = models.BooleanField(default=False,verbose_name="是否互相关注",db_comment="是否互相关注")

    mutual_time = models.DateTimeField(null=True,blank=True,verbose_name="互关时间",db_comment="互关时间")

    class Meta:
        db_table = "tb_fans"
        unique_together = ("user","fans")

class Advice(models.Model):
    """
    公告表
    标题、 内容、 发布时间、状态、录入时间、修改时间、是否删除
    """
    title = models.CharField(max_length=128,verbose_name="标题",db_comment="标题")

    content = models.TextField(verbose_name="内容",db_comment="内容")

    publish_time = models.DateTimeField(verbose_name="发布时间",db_comment="发布时间")

    state = models.BooleanField(max_length=1,default="0",verbose_name="状态",db_comment="状态")

    create_time = models.DateTimeField(auto_now_add=True,verbose_name="录入时间",db_comment="录入时间")

    update_time = models.DateTimeField(verbose_name="修改时间",db_comment="修改时间")

    is_deleted = models.BooleanField(default=False,verbose_name="是否删除",db_comment="是否删除")

    class Meta:
        db_table = "tb_advice"

class AdviceRead(models.Model):
    """
    公告阅读表
    用户(关系属性)、公告(关系属性)、 阅读时间
    """
    user = models.ForeignKey(to='auth.User',on_delete=models.CASCADE,
                             verbose_name="用户",db_comment="用户")

    advice = models.ForeignKey(to='Advice',on_delete=models.CASCADE,
                                 verbose_name="公告",db_comment="公告")

    read_time = models.DateTimeField(auto_now_add=True,verbose_name="阅读时间",db_comment="阅读时间")

    class Meta:
        db_table = "tb_advice_read"
        unique_together = ("user","advice")

class Notify(models.Model):
    """
    通知表
    通知类型 、 通知内容、用户(关系属性)、 通知时间、 是否已读、 读取时间 、
    """
    type = models.CharField(max_length=64,verbose_name="通知类型",db_comment="通知类型")

    user = models.ForeignKey(to='auth.User',on_delete=models.CASCADE,
                             verbose_name="用户",db_comment="用户")

    content = models.TextField(verbose_name="内容",db_comment="内容")

    publish_time = models.DateTimeField(verbose_name="发布状态",db_comment="发布状态")

    state = models.BooleanField(verbose_name="状态",db_comment="状态",default=False)

    create_time = models.DateTimeField(auto_now_add=True,verbose_name="录入时间",db_comment="录入时间")

    class Meta:
        db_table = "tb_notify"


class Letter(models.Model):
    """
    私信表
    发送用户(关系属性)、 接收用户(关系属性)、 私信内容、 发送时间、 是否已读、 读取时间
    """
    sender = models.ForeignKey(to='auth.User',on_delete=models.CASCADE,
                             related_name="sender",
                             verbose_name="发送用户",db_comment="发送用户")

    receiver = models.ForeignKey(to='auth.User',on_delete=models.CASCADE,
                                 related_name="receiver",
                                 verbose_name="接收用户",db_comment="接收用户")

    content = models.TextField(verbose_name="内容",db_comment="内容")

    send_time = models.DateTimeField(auto_now_add=True,verbose_name="发送时间",db_comment="发送时间")

    is_read = models.BooleanField(default=False,verbose_name="是否已读",db_comment="是否已读")

    read_time = models.DateTimeField(null=True,blank=True,verbose_name="读取时间",db_comment="读取时间")

    class Meta:
        db_table = "tb_letter"


class Swiper(models.Model):
    """
    轮播图/广告表
    图片地址 、超链接地址 、是否启用 、是轮播图还是广告、  录入时间、是否删除
    """
    image = models.ImageField(upload_to="swiper/",verbose_name="图片地址",db_comment="图片地址")

    link = models.CharField(max_length=128,verbose_name="超链接地址",db_comment="超链接地址")

    type = models.CharField(max_length=10,choices=(("0","轮播图"),("1","广告")),
                            verbose_name="类型",db_comment="类型",default="0")

    create_time = models.DateTimeField(auto_now_add=True,verbose_name="录入时间",db_comment="录入时间")

    is_deleted = models.BooleanField(default=False,verbose_name="是否删除",db_comment="是否删除")

    class Meta:
        db_table = "tb_swiper"